import { archService } from "@/mdesign-lib/mdesign-app.umd.js";
import { Action } from "@/mdesign-lib/mdesign-app.umd.js";
import { ActionKey } from "@/mdesign-lib/mdesign-app.umd.js";
import { shell } from "electron";

export class OpenRequireAction extends Action {
  keyName = "openRequire" as ActionKey;
  desc = "openRequire";

  async run() {
    const requireAddress = app.global.requireAddress;
    const user = app.global.user;
    if (user && requireAddress) {
      let baseURL = requireAddress;
      if (!baseURL.startsWith("http://")) {
        baseURL = "http://" + baseURL;
      }
      const res = await archService.autoLoginRequire(baseURL, user.userName);
      shell.openExternal(res);
    }
  }

  onSysMenuClick() {
    this.run();
  }
}
